<?php
include_once "db.php";
// if($_POST[f_name] == "") {
 //  $error = "true";
 //  $_POST[f_name] = "error";
 // }
  
  //if($_POST[l_name] == "") {
  // $error = "true";
  // $_POST[l_name] = "error";
 // }

   if($_POST[contact_type] == "") {
  $error = "true";
   $_POST[contact_type] = "error";
  } 
 
   if($_POST[problem_type] == "") {
   $error = "true";
   $_POST[problem_type] = "error";
  } 
//  if($_POST[Problem] == "") {
 //  $error = "true";
 //  $_POST[Problem] = "error";
 // } 
  if($_POST[call_closed] == "") {
   $error = "true";
   $_POST[call_closed] = "error";
  }
  if($_POST[transfered] == "true") {
  	if ($_POST[transfer_to] == "") {
  	//	$error = "true";
 	 //	$_POST[transfered] = "error"; 
     
  		header("Location: transfer_phonecall.php?error=true");
		exit;
 		}
  }

   if ($error) {
  header("Location: phonecall.php?error=true&f_name=$_POST[f_name]&l_name=$_POST[l_name]&email=$_POST[email]&problem_type=$_POST[problem_type]&Problem=$_POST[Problem]&call_closed=$_POST[call_closed]&notes=$_POST[notes]&KNum=$_POST[KNum]&pipelineuserid=$_POST[pipelineuserid]&dayphone=$_POST[dayphone]&problem_type=$_POST[problem_type]");
 }
 else {
  

  
	mysql_query ("insert into Calls (first_name, last_name, pipeline_userid, KNum, birthdate, day_phone, problem_desc, email, problem_type, call_closed, helpdesk_user, higher_level, pending, cont_type) values('$_POST[f_name]','$_POST[l_name]', '$_POST[pipelineuserid]', '$_POST[KNum]','$_POST[birthdate]','$_POST[dayphone]', '$_POST[Problem]', '$_POST[email]', '$_POST[problem_type]', '$_POST[call_closed]', '$_POST[HDuserID]', '$_POST[high_level]', '$_POST[pending]', 'phone')");
	
$id = mysql_insert_id();
	
mysql_query ("insert into resolution_notes (call_ID,HD_user_ID,note_desc, contact_type, pipeline_reset, transfer_to) values ('$id','$_POST[HDuserID]', '$_POST[notes]', '$_POST[contact_type]', '2', '$_POST[transfer_to]')"); 

// opening connections to the various dbse tables to retrieve descriptions associated with items and set returned data into variables for email 


$problem = mysql_query("select * from problem_type where PT_ID LIKE '$_POST[problem_type]'");
$user_problem= mysql_fetch_object($problem) ;
$user_problem->PT_desc ;


if ($_POST[call_closed] == 1) {
		
	//Send Email
	$to = "Online Support < online@sbcc.edu >";
	
	// subject
	$subject = "WebForm-" .$user_problem->PT_desc ;
	
	// message
	$message = "First Name: " .$_POST[f_name]. "\n\n";
	$message .= "Last Name:".$_POST[l_name]."\n\n" ;
	$message .= "Phone:" .$_POST[dayphone]."\n\n" ;
	$message .= "Problem:" .$_POST[Problem]."\n\n" ;
	$message .= "Email:" .$_POST[email]. "\n\n" ;
	$message .= "Problem Type:" .$user_problem->PT_desc . "\n\n" ;
	$headers = "From: " . $_POST[email] ;
	$headers .= "\r\nContent-type: text/plain";
	
	// Mail it
	//mail($to, $subject, $message, $headers);
	header("Location: calls.php?active=1");
	}

elseif ($_POST[call_closed]== 2) {

	header("Location: calls.php?active=1");

}
}

?>